<?php
/**
 * Author: 式神(vashi)
 * email: 289650682@qq.com
 * Date: 2019/3/13 15:10
 * FileName: Collection.php
 */

namespace app\cms\controller;


use app\cms\model\CollectionNode;
use app\common\controller\Common;

class Collection extends Common
{
    protected $middleware = ['Auth'];

    protected function initialize()
    {
        parent::initialize();
        $this->db = new CollectionNode();
    }

    public function index(){
        $input=input('get.');
        $input['rows'] = isset($input['rows']) ? $input['rows'] : config('rows');
        $input['page'] = isset($input['page']) ? $input['page'] : 1;

        $map = $this->getMap($input);
        $order = $this->getOrder($input);
        $res['total'] = $this->db->where($map)->order($order)->count();
        $data= $this->db->where($map)->order($order)->limit($input['rows'])->page($input['page'])->select();
        $res['rows'] =$data;
        $res['page'] =$input['page'];
        $d=[
            "code"=>0,
        ];
        $d['data']=$res;
        return json($d);
    }
    //添加
    public function add(){
        $res=$this->db->add(input('post.'));
        return json($res);
    }
    //编辑
    public function edit(){
        $res=$this->db->edit(input('post.'));
        return json($res);
    }
    //删除
    public function del(){
        $res=$this->db->del(input('post.'));
        return json($res);
    }
}